#include <stdio.h>

#define TRACE(x...) x
#define PRINT(x...) TRACE(printf(x))

int pas[2010][1010];
int w, h, k;
int a, b, c, d;
int q;
int ans;
int t;
int mult;

int main() {
	for (int i=0; i<2005; i++) {
		pas[i][0]=1;
		pas[i][i]=1;
	}

	for (int i=1; i<2005; i++) {
		for (int j=1; j<1005; j++) {
			pas[i][j] = pas[i-1][j-1]+pas[i-1][j]; 
			pas[i][j]%=2552;
		}
	}

	scanf("%d", &t);

	while (t--) {
		scanf("%d %d %d", &w, &h, &k);
		ans=pas[w+h][h];

		for (int i=0; i<k; i++) {
			scanf("%d", &q);			
			ans=pas[w+h][h];
			
			for (int j=0; j<q; j++) {
				scanf("%d %d %d %d", &a, &b, &c, &d);

				mult=(pas[a+b][b])*(pas[(w-c)+(h-d)][h-d]);
				mult%=2552;
				ans-=mult;
				ans+=2552; ans%=2552;		
			}
			
			printf("%d\n", ans);	
		}
	}	

	return 0;
}
